//
//  HCComposeToolBar.swift
//  Hweibome
//
//  Created by 何川 on 15/12/16.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit

enum HCComposeToolBarButtonType: Int {
    case Picture = 0 //图片
    case Mention = 1 //@
    case Trend = 2 //话题
    case Emotion = 3 //表情
    case Add = 4 //加
}

@available(iOS 9.0, *)
class HCComposeToolBar: UIStackView {
//闭包A
    var childButtonClickClosure:((type:HCComposeToolBarButtonType) ->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        axis = .Horizontal
        distribution = .FillEqually
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = UIColor.redColor()
        
        addChildButton("compose_toolbar_picture",type: .Picture)
        addChildButton("compose_mentionbutton_background",type: .Mention)
        addChildButton("compose_trendbutton_background", type: .Trend)
        addChildButton("compose_emoticonbutton_background", type: .Emotion)
        addChildButton("compose_add_background",type: .Add)
    }

    private func addChildButton(imgName: String , type: HCComposeToolBarButtonType)
    {
        let button = UIButton()
        button.tag = type.rawValue
        button.addTarget(self, action: "childButtonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "\(imgName)_highlighted"), forState: UIControlState.Highlighted)
        button.backgroundColor = UIColor(patternImage: UIImage(named: "compose_toolbar_background")!)
        addArrangedSubview(button)
    }
    //监听方法
    //闭包A
    @objc private func childButtonClick(button:UIButton) {
        childButtonClickClosure?(type: HCComposeToolBarButtonType(rawValue: button.tag)!)
    }
}
